# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Kozak Ivan <kozak-iv@yandex.ru>
# Maintainer: Kozak Ivan <kozak-iv@yandex.ru>
pkgname=nut
pkgver=2.7.4
pkgrel=6
pkgdesc="Network UPS tools"
url="http://www.networkupstools.org"
arch="all"
license="GPL"
depends_dev="openssl-dev libusb-compat-dev net-snmp-dev neon-dev"
makedepends="$depends_dev libtool autoconf automake"
pkgusers=$pkgname
pkggroups=$pkgname
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-dev"
source="http://www.networkupstools.org/source/2.7/$pkgname-$pkgver.tar.gz
	openssl-1.1.patch
	upsd.initd
	upsmon.initd
	"
builddir="$srcdir/$pkgname-$pkgver"

prepare() {
	default_prepare
	autoreconf -vif
}

build() {
	cd "$builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--libexecdir=/usr/lib/nut \
		--without-wrap \
		--with-user=$pkgname \
		--with-group=$pkgname \
		--disable-static \
		--with-serial \
		--with-usb \
		--without-avahi \
		--with-snmp \
		--with-neon \
		--without-powerman \
		--without-ipmi \
		--without-freeipmi \
		--with-libltdl \
		--without-cgi \
		--with-drvpath=/usr/lib/nut \
		--datadir=/usr/share/nut \
		--sysconfdir=/etc/nut \
		--with-statepath=/var/run/nut \
		--with-altpidpath=/var/run/nut \
		--with-openssl
	make
}

check() {
	make -C "$builddir" check
}

package() {
	make -C "$builddir" DESTDIR="$pkgdir" install
	install -Dm755 "$srcdir"/upsd.initd "$pkgdir"/etc/init.d/nut-upsd
	install -Dm755 "$srcdir"/upsmon.initd "$pkgdir"/etc/init.d/nut-upsmon
	install -d -o $pkgname -g $pkgname "$pkgdir"/var/lib/$pkgname

	local file;
	for file in "$pkgdir"/etc/nut/*.sample; do
		chmod 640 $file
		chown root:$pkgname $file
		mv $file ${file%.sample}
	done
}

sha512sums="320c4aff85d8a370c5eff77d33924fdfc3caf6a250620693cdd5bf3336b3a80d8a207488eee841bcf8b72fbad68fda4c074e63b99c56e7886716fc934122d11a  nut-2.7.4.tar.gz
2b6f5df0c7084a0e86474b36d4c567b995c76e2f8fda788a7dffa6d8ecd6b41698ca8376ac228cdbfd805e3406611e7f003e4492d98c74658ed785d7320ab866  openssl-1.1.patch
f470da96f9d324173e9bd241146284793738f99f2314dfe41c3ac3d56234394609b47d7e593ce9940ec7ce74a26a8483d0911161a16402cd3cc25023ba991d4b  upsd.initd
32470ae473fc363131787cd57f13d40763898947d56d032790ba7f3a5eaa8038b602f7e395ca44f6c5adce8ee5ec496e30ca0eaadb3c78a38015677aea751e12  upsmon.initd"
